<template>
  <div class="container">
    <!-- <el-header> -->
    <div class="title">新增课程</div>
    <div>
      <el-steps
        :active="active"
        align-center
      >
        <el-step
          :status="getStatus(active,'1')"
          title="填写课程基本信息"
        />
        <el-step
          :status="getStatus(active,'2')"
          title="创建课程大纲"
        />
        <el-step
          :status="getStatus(active,'3')"
          title="最终发布"
        />
      </el-steps>
    </div>
    <div v-if="active==1">
      <div
        style="width: 80%;margin-left: 10%"
        class="app-container"
      >
        <template>
          <el-form
            ref="courseForm"
            :model="courseForm"
            :rules="courseFormRules"
            label-width="100px"
            class="demo-form-inline"
          >
            <el-form-item
              label="课程标题"
              prop="title"
            >
              <el-input
                v-model="courseForm.title"
                type="text"
                placeholder="请输入课程标题"
              />
            </el-form-item>

            <!-- <el-form-item
              label="课程分类"
              prop="cate_id"
            >
              <el-select
                v-model="ruleForm.courseTeather"
                placeholder="请选择课程讲师"
              >
                <el-option
                  label="数码产品"
                  value="1"
                />
                <el-option
                  label="美妆"
                  value="2"
                />
                <el-option
                  label="医药"
                  value="3"
                />
              </el-select>

              <el-select
                v-model="ruleForm.courseTeather"
                placeholder="请选择课程讲师"
                style="margin-left: 10px;"
              >
                <el-option
                  label="数码产品"
                  value="1"
                />
                <el-option
                  label="美妆"
                  value="2"
                />
                <el-option
                  label="医药"
                  value="3"
                />
              </el-select>
            </el-form-item> -->

            <el-form-item
              label="课程讲师"
              prop="teacherName"
            >
              <el-input
                placeholder="请输入课程讲师"
                v-model="courseForm.teacherName"
              />
            </el-form-item>

            <!-- <el-form-item
              label="课程讲师"
              prop="cate_id"
            >
              <el-select
                v-model="ruleForm.courseTeather"
                placeholder="请选择课程讲师"
              >
                <el-option
                  label="数码产品"
                  value="1"
                />
                <el-option
                  label="美妆"
                  value="2"
                />
                <el-option
                  label="医药"
                  value="3"
                />
              </el-select>
            </el-form-item> -->

            <!-- <el-form-item
              label="总课时"
              prop="courseName"
              placeholder="请输入总课时"
            >
              <el-input
                v-model="ruleForm.courseName"
                type="number"
                style="width:20%;"
              />
            </el-form-item> -->
            <el-form-item
              label="课程简介"
              prop="description"
            >
              <el-input
                v-model="courseForm.description"
                type="textarea"
                :rows="4"
                placehoder="请输入课程简介"
              />
            </el-form-item>

            <el-form-item
              label="课程封面"
              prop="imageUrl"
            >
              <el-upload
                class="avatar-uploader"
                style="text-align:left;padding-bottom:0"
                action="http://localhost:9999/file/upload_re"
                accept=".jpg,.jpeg,.png,.gif,.JPG,.JPEG,.PBG,.GIF,"
                :headers="{
                'X-Token':token
              }"
                :data={fileType:1}
                :file-list="fileList1"
                name="files"
                :on-success="handleAvatarSuccess1"
                :on-remove="handleRemove1"
              >
                <img
                  v-if="imageData"
                  :src="getImageURL"
                  class="avatar"
                >
                <i
                  v-else
                  class="el-icon-plus avatar-uploader-icon"
                />
              </el-upload>
            </el-form-item>

            <el-form-item>
              <el-button
                type="primary"
                @click="onSubmit"
              >保存并下一步</el-button>
            </el-form-item>

            <el-form-item>
              <!-- <video
                :src="getVideoURL"
                controls
                v-if="videoData"
              ></video> -->
            </el-form-item>

          </el-form>
        </template>
      </div>
    </div>
    <div v-if="active==2">
      <div
        style="width: 80%;margin-left: 10%"
        class="app-container"
      >
        <div>
          <el-button
            type="text"
            @click="addChapters()"
          >添加章节</el-button>
        </div>
        <div>
          <div
            v-for="(item,index) in chapterData"
            :key="index"
          >
            <div class="chapterItem">
              <el-row>
                <el-col :span="20">
                  {{item.chapterTitle}}
                </el-col>

                <el-col
                  :span="4"
                  style="text-align:right"
                >
                  <el-button
                    @click="barItemAdd(item)"
                    type="text"
                    class="operaBtn"
                  >添加小结</el-button>
                  <el-button
                    @click="chapterItemEdit(item.chapterId)"
                    type="text"
                    class="operaBtn"
                  >编辑</el-button>
                  <el-button
                    type="text"
                    class="operaBtn"
                  >删除</el-button>
                </el-col>
              </el-row>
            </div>
            <div
              v-for="(item1,index1) in item.children"
              :key="index1"
            >
              <div class="chapterItem1">
                <el-row>
                  <el-col :span="22">
                    {{item1.barTitle}}
                  </el-col>

                  <el-col
                    :span="2"
                    style="text-align:right"
                  >
                    <el-button
                      @click="barItemEdit(item.chapterId,item1.barId)"
                      type="text"
                      class="operaBtn"
                    >编辑</el-button>
                    <el-button
                      type="text"
                      class="operaBtn"
                    >删除</el-button>
                  </el-col>
                </el-row>
              </div>
            </div>

          </div>
        </div>
        <div>
          <el-button
            type="defult"
            @click="last"
          >上一步</el-button>
          <el-button
            type="primary"
            style="margin-left: 10px"
            @click="add"
          >下一步</el-button>
        </div>
      </div>

      <el-dialog
        :title="chapterDialogType == 'add'?'添加章节':'编辑章节'"
        :visible.sync="chapterVisible"
        width="650px"
        :destroy-on-close=true
      >
        <el-form
          ref="chapterForm"
          :model="chapterForm"
          :rules="chapterFormRules"
        >
          <el-form-item
            label="章节标题"
            label-width="120px"
            prop="chapterTitle"
          >
            <el-input
              v-model="chapterForm.chapterTitle"
              autocomplete="off"
              style="width:90%"
            />
          </el-form-item>
          <el-form-item
            label="章节排序"
            label-width="120px"
            prop="chapterSort"
          >
            <el-input
              v-model="chapterForm.chapterSort"
              autocomplete="off"
              type="number"
              style="width:30%"
            />
          </el-form-item>
        </el-form>
        <div
          slot="footer"
          class="dialog-footer"
        >
          <el-button @click="chapterFormCancle">取 消</el-button>
          <el-button
            type="primary"
            @click="chapterFormOk"
          >确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog
        :title="barDialogType == 'add'?'添加课时':'编辑课时'"
        :visible.sync="barVisible"
        width="650px"
        :destroy-on-close=true
      >
        <el-form
          ref="barForm"
          :model="barForm"
          :rules="barFormRules"
        >
          <el-form-item
            label="课时标题"
            label-width="120px"
            prop="barTitle"
          >
            <el-input
              v-model="barForm.barTitle"
              autocomplete="off"
              style="width:90%"
            />
          </el-form-item>
          <el-form-item
            label="课时排序"
            label-width="120px"
            prop="barSort"
          >
            <el-input
              v-model="barForm.barSort"
              autocomplete="off"
              type="number"
              style="width:30%"
            />
          </el-form-item>
          <el-form-item
            label="上传视频"
            label-width="120px"
            prop="barVideo"
          >
            <el-upload
              class="upload-demo"
              action="http://localhost:9999/file/upload_re"
              accept=".mp4,.avi"
              :headers="{
                'X-Token':token,
              }"
              :data={fileType:2}
              name="files"
              :on-success="handleAvatarSuccess2"
              :multiple="false"
              :file-list="fileList2"
            >
              <el-button type="primary">上传视频</el-button>
              <i
                slot="tip"
                style="margin-left:10px"
                class="el-icon-question"
              ></i>
            </el-upload>
          </el-form-item>

          <el-form-item
            label="上传资料"
            label-width="120px"
            prop="barAnnex"
          >
            <el-upload
              class="upload-demo"
              action="http://localhost:9999/file/upload_re"
              accept=".pdf, .doc, .docx, .xls, .xlsx,.zip,.rar"
              :headers="{
                'X-Token':token,
              }"
              name="files"
              :on-success="handleAvatarSuccess3"
              :multiple="false"
              :data={fileType:3}
              :file-list="fileList3"
            >
              <el-button type="primary">上传资料</el-button>
              <i
                slot="tip"
                style="margin-left:10px"
                class="el-icon-question"
              ></i>
            </el-upload>
          </el-form-item>
        </el-form>
        <div
          slot="footer"
          class="dialog-footer"
        >
          <el-button @click="barFormCancle">取 消</el-button>
          <el-button
            type="primary"
            @click="barFormOk"
          >确 定</el-button>
        </div>
      </el-dialog>
    </div>
    <div v-if="active==3">
      <div style="width: 80%;margin-left: 10%">
        <el-row>
          <el-col :span="12">
            <!-- <img
              style="float:right"
              src="http://sem.g3img.com/g3img/hqys2016/20160618193759_85684.jpg"
            /> -->
            <img
              v-if="imageData"
              :src="getImageURL"
              class="avatar"
              style="width:100%;height:100%"
            >
          </el-col>
          <el-col :span="12">
            <div class="active3Span">{{ courseSumit.title }}</div>
            <div class="active3Span">共{{getCharacterNum}}个章节</div>
            <!-- <div class="active3Span">所属分类 :</div> -->
            <div class="active3Span">课程主讲 :{{ courseSumit.teacherName }}</div>
          </el-col>
        </el-row>
        <div style="margin-top:15px">
          <el-button
            type="defult"
            @click="cancelActive2"
          >返回修改</el-button>
          <el-button
            type="primary"
            style="margin-left: 10px"
            @click="publishCourses"
          >发布课程</el-button>
        </div>
      </div>
    </div>
    <!-- <el-button
      type="primary"
      style="margin-top: 10px"
      @click="nextTo(active)"
    >下一步</el-button> -->
    <!-- </el-header> -->

  </div>
</template>

<script>
import questionBank from "@/api/questionBank";
import getCourse from "@/api/course";
import utils from "@/utils/utils";
import { getToken } from "@/utils/auth";
import axios from "axios";

export default {
  name: "QuestionBankManage",
  data() {
    var validateChapterSort = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("章节排序不能为空"));
      }
      setTimeout(() => {
        const reg = /^[1-9]\d*$ /;
        if (reg.test(value)) {
          callback(new Error("请输入正整数"));
        } else {
          callback();
        }
      }, 1000);
    };

    var validateBarSort = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("课时排序不能为空"));
      }
      setTimeout(() => {
        const reg = /^[1-9]\d*$ /;
        if (reg.test(value)) {
          callback(new Error("请输入正整数"));
        } else {
          callback();
        }
      }, 1000);
    };

    var validateChapterTitle = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("章节标题不能为空"));
      }
      setTimeout(() => {
        callback();
      }, 1000);
    };
    return {
      imageData: null, // 用于存储图片数据的变量
      videoData: null, // 存储视频数据的变量
      imgSrcCourse: "",
      courseSumit: {},
      characterSumit: [],
      fileList1: [],
      fileList2: [],
      fileList3: [],
      token: getToken(),
      active: 1,
      courseForm: {
        title: "",
        teacherName: "",
        description: "",
        imageUrl: "",
      },
      courseFormRules: {
        title: [{ required: true, message: "请输入课程标题", trigger: "blur" }],
        teacherName: [
          { required: true, message: "请输入课程讲师", trigger: "blur" },
        ],
        description: [
          { required: true, message: "请输入课程简介", trigger: "blur" },
        ],
        imageUrl: [
          { required: true, message: "请上传课程封面", trigger: "blur" },
        ],
      },
      chapterVisible: false,
      chapterDialogType: "add",
      chapterForm: {
        chapterTitle: "", // 章节标题
        chapterSort: 1, // 章节排序
        chapterId: 1,
      },
      chapterData: [], // 章节数据
      chapterItemEditId: null, //修改章节index
      chapterFormRules: {
        chapterTitle: [{ validator: validateChapterTitle, trigger: "blur" }],
        chapterSort: [{ validator: validateChapterSort, trigger: "blur" }],
      },
      barVisible: false, //小结弹窗
      barDialogType: "add",
      barForm: {
        barTitle: "", // 课时标题
        barSort: 0, // 课时排序
        barVideo: "", //上传视频
        barId: 1,
        barAnnex: "", //上传资料
      },
      barItemEditId: null, //修改章节index
      fileList: [], //视频列表
      barFormRules: {
        barTitle: [
          { required: true, message: "请输入课时标题", trigger: "blur" },
        ],
        barSort: [{ validator: validateBarSort, trigger: "blur" }],
        barVideo: [
          { required: true, message: "请上传课时视频", trigger: "blur" },
        ],
      },

      queryInfo: {
        bankName: "",
        pageNo: 1,
        pageSize: 10,
      },
      // 被选中的表格的信息
      selectedTable: [],
      // 所有题库信息
      questionBankInfo: [],
      // 当前被选中的操作
      operation: "",
      loading: true,
      // 所有的题库条数
      total: 0,
      // 添加题库的对话框
      addTableVisible: false,
      // 添加题库的表单信息
      addForm: {
        bankName: "",
      },
    };
  },
  created() {
    console.log("-------------------", this.token);
    this.getBankInfo();
  },
  computed: {
    getCharacterNum() {
      let num = 0;
      this.characterSumit.map((item) => {
        num = num + item.sectionList.length;
      });
      return num;
    },
    getImageURL() {
      if (this.imageData) {
        // 将二进制流数据转换为 Base64 格式的 URL
        const base64Data = btoa(
          new Uint8Array(this.imageData).reduce(
            (data, byte) => data + String.fromCharCode(byte),
            ""
          )
        );
        return `data:image/jpeg;base64,${base64Data}`;
      }
      return null;
    },
    getVideoURL() {
      if (this.videoData) {
        // 将二进制流数据转换为 Blob 对象
        const blob = new Blob([this.videoData], { type: "video/mp4" });
        return URL.createObjectURL(blob);
      }
      return null;
    },
  },
  methods: {
    // 文件预览
    fetchImageData(obj) {
      axios
        .get(`/file/preview/${obj.fileName}`, {
          responseType: "arraybuffer",
          headers: { "X-Token": this.token },
        })
        .then((response) => {
          // 将二进制流数据存储在 imageData 变量中
          this.imageData = response.data;
        })
        .catch((error) => {
          console.error(error);
        });
    },
    fetchVideoData() {
      let obj = {
        fileName: "6d41ec9e-0484-4da0-8455-02105a41465c.mp4",
        // fileName:this.fileList1[0].fileName,
      };
      axios
        .get(`/file/preview/${obj.fileName}`, {
          responseType: "arraybuffer",
          headers: { "X-Token": this.token },
        })
        .then((response) => {
          // 将二进制流数据存储在 videoData 变量中
          this.videoData = response.data;
        })
        .catch((error) => {
          console.error(error);
        });
    },
    // 发布课程
    publishCourses() {
      let obj = {
        characterList: this.characterSumit,
        course: this.courseSumit,
      };
      getCourse.addCourse(obj).then((res) => {
        if (res.code === 20000) {
          this.$message({
            message: "添加课程成功",
            type: "success",
          });
          this.$router.push({ path: "/examManage/courseIndex" });
        } else {
          this.$notify({
            title: "Tips",
            message: res.message,
            type: "error",
            duration: 2000,
          });
        }
      });
    },

    //下一步
    add() {
      console.log("----------", this.chapterData);
      console.log("----------", this.fileList2);
      console.log("----------", this.fileList3);
      let arr = JSON.parse(JSON.stringify(this.chapterData));
      arr = arr.map((item) => {
        item = {
          chapterName: item.chapterTitle,
          chapterOrder: item.chapterSort,
          sectionList: item.children,
        };
        console.log("-------item------", item);
        item.sectionList = item.sectionList.map((item1) => {
          item1 = {
            sectionName: item1.barTitle,
            sectionOrder: item1.barSort,
            sectionFiles: item1.fileList,
          };
          return item1;
        });
        return item;
      });
      console.log("arr-----------", arr);

      let isBoolean = false;
      arr.map((item) => {
        if (item.sectionList.length == 0) {
          isBoolean = true;
        }
      });
      if (isBoolean) {
        this.$message({
          showClose: true,
          message: "每一个章节必须有一个小节",
          type: "warning",
        });
      } else {
        this.characterSumit = arr;
        this.active = this.active + 1;
      }
    },
    cancelActive2() {
      this.active = this.active - 1;
    },
    last() {
      this.active = this.active - 1;
    },
    // 添加章节
    addChapters() {
      this.chapterForm.chapterSort = this.chapterData.length + 1;
      this.chapterDialogType = "add";
      this.chapterVisible = true;
    },
    //添加章节弹窗取消
    chapterFormCancle() {
      this.$refs["chapterForm"].resetFields();
      this.chapterDialogType = "add";
      this.chapterVisible = false;
      this.chapterItemEditId = null;
    },
    //添加章节弹窗确认
    chapterFormOk() {
      console.log("error submit!!");
      this.$refs["chapterForm"].validate((valid) => {
        if (valid) {
          console.log("submit!!", this.chapterForm);
          const { chapterTitle, chapterSort } = this.chapterForm;
          if (this.chapterDialogType == "add") {
            this.chapterData.push({
              ...this.chapterForm,
              chapterId: this.chapterData.length + 1,
              children: [],
            });
            this.chapterData.sort((a, b) => a.chapterSort - b.chapterSort);
          } else {
            this.chapterData = this.chapterData.map((item) => {
              if (item.chapterId == this.chapterItemEditId) {
                item = {
                  ...item,
                  chapterTitle,
                  chapterSort,
                };
              }
              return item;
            });
            this.chapterData.sort((a, b) => a.chapterSort - b.chapterSort);
          }
          this.$refs["chapterForm"].resetFields();
          this.chapterVisible = false;
          this.chapterItemEditId = null;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //章节编辑
    chapterItemEdit(chapterId) {
      this.chapterDialogType = "edit";
      this.chapterItemEditId = chapterId;
      this.chapterVisible = true;
      this.chapterForm = {
        ...this.chapterData.find((item) => item.chapterId == chapterId),
      };
    },
    //添加小节
    barItemAdd(item) {
      this.chapterItemEditId = item.chapterId;
      this.barForm.barSort = item.children.length + 1;
      this.barDialogType = "add";
      this.barVisible = true;
    },
    //编辑小节
    barItemEdit(chapterId, barId) {
      this.chapterItemEditId = chapterId;
      this.barItemEditId = barId;
      this.barDialogType = "edit";
      this.barVisible = true;
      this.barForm = {
        ...this.chapterData
          .find((item) => item.chapterId == chapterId)
          .children.find((item1) => item1.barId == barId),
      };
    },
    //添加小节取消
    barFormCancle() {
      this.$refs["barForm"].resetFields();
      this.barDialogType = "add";
      this.barVisible = false;
      this.chapterItemEditId = null;
      this.fileList2 = [];
      this.fileList3 = [];
    },
    //视频上传变化
    uploadSuccess(file, fileList) {
      console.log(file);
      console.log(fileList);
    },
    //添加小节确认
    barFormOk() {
      this.$refs["barForm"].validate((valid) => {
        if (valid) {
          const { barTitle, barSort, barVideo } = this.barForm;
          if (this.barDialogType == "add") {
            let arr = this.chapterData.find(
              (item) => item.chapterId == this.chapterItemEditId
            ).children;
            arr.push({
              ...this.barForm,
              barId: arr.length + 1,
              fileList: [...this.fileList2, ...this.fileList3],
            });
            arr.sort((a, b) => a.barSort - b.barSort);
            this.chapterData = this.chapterData.map((item) => {
              if (item.chapterId == this.chapterItemEditId) {
                item.children = arr;
              }
              return item;
            });
          } else {
            let arr = this.chapterData.find(
              (item) => item.chapterId == this.chapterItemEditId
            ).children;
            arr = arr.map((item) => {
              if (item.barId == this.barItemEditId) {
                item = {
                  ...item,
                  barTitle,
                  barSort,
                  barVideo,
                  fileList: [...this.fileList2, ...this.fileList3],
                };
              }
              return item;
            });
            arr.sort((a, b) => a.barSort - b.barSort);
            this.chapterData = this.chapterData.map((item) => {
              if (item.chapterId == this.chapterItemEditId) {
                item.children = arr;
              }
              return item;
            });
          }

          console.log(this.chapterData);
          this.$refs["barForm"].resetFields();
          this.barVisible = false;
          this.chapterItemEditId = null;
          this.fileList2 = [];
          this.fileList3 = [];
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 课程基本信息
    onSubmit() {
      this.$refs["courseForm"].validate((valid) => {
        if (valid) {
          console.log("submit!!", this.courseForm);
          this.courseSumit = {
            coverFileId: this.fileList1[0].fileId, //封面id
            coverFileName: this.fileList1[0].fileName, //封面url
            title: this.courseForm.title, //课程标题
            teacherName: this.courseForm.teacherName, //课程讲师
            description: this.courseForm.description, //课程简介
          };
          // this.fetchImageData();
          // this.fetchVideoData();
          console.log("提交的课程数据", this.courseSumit);
          this.active++;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    nextTo(active) {
      this.active = active + 1;
    },
    //移除1
    handleRemove1(file, fileList) {
      console.log(file, fileList, this.fileList1);
      this.fileList1 = this.fileList1.filter(
        (item) => item.fileId != file.fileId
      );
      this.imageData = null;
      console.log(this.fileList1);
    },
    handleAvatarSuccess1(_, file, fileList) {
      const { name, response } = file;
      this.courseForm.imageUrl = response.data.fileId;
      this.fetchImageData({ fileName: response.data.fileName });
      this.fileList1 = [
        {
          name,
          fileName: response.data.fileName,
          url: response.data.fileName,
          fileId: response.data.fileId,
        },
      ];
      console.log("-----", response, file, fileList);
    },
    handleAvatarSuccess2(_, file, fileList) {
      const { name, response } = file;
      this.barForm.barVideo = response.data.fileId;
      this.fileList2 = [
        {
          name,
          fileName: response.data.fileName,
          url: response.data.fileName,
          fileId: response.data.fileId,
          fileType: "2",
        },
      ];
      console.log("-----", response, file, fileList);
    },
    handleAvatarSuccess3(_, file, fileList) {
      const { name, response } = file;
      // this.courseForm.imageUrl = response.data.fileId;
      this.fileList3.push({
        name,
        fileName: response.data.fileName,
        url: response.data.fileName,
        fileId: response.data.fileId,
        fileType: "2",
      });

      console.log("-----", response, file, fileList);
    },
    beforeAvatarUpload() {},
    getStatus(status, key) {
      // status判断
      // eslint-disable-next-line eqeqeq
      if (key === "1") {
        return "finish";
      } else if (key === "2") {
        if (status === 1) {
          return "wait";
        } else {
          return "finish";
        }
      } else {
        if (status === 1 || status === 2) {
          return "wait";
        } else {
          return "finish";
        }
      }
    },
    // 获取所有的题库信息
    getBankInfo() {
      questionBank.getBankHaveQuestionSumByType(this.queryInfo).then((res) => {
        if (res.code === 20000) {
          this.questionBankInfo = res.data.data;
          this.total = res.data.total;
          this.loading = false;
        } else {
          this.$notify({
            title: "Tips",
            message: res.message,
            type: "error",
            duration: 2000,
          });
        }
      });
    },
    // 查询内容变化
    contentChange() {
      this.getBankInfo();
    },
    // 操作选项的被触发
    operationChange(val) {
      if (val === "delete") {
        this.$confirm("此操作将永久删除该题库, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            const ids = [];
            this.selectedTable.map((item) => {
              ids.push(item.questionBank.bankId);
            });
            // 发起删除请求
            questionBank
              .deleteQuestionBank({ ids: ids.join(",") })
              .then((resp) => {
                if (resp.code === 20000) {
                  this.$notify({
                    title: "Tips",
                    message: resp.message,
                    type: "success",
                    duration: 2000,
                  });
                  this.getBankInfo();
                } else {
                  this.$notify({
                    title: "Tips",
                    message: resp.message,
                    type: "error",
                    duration: 2000,
                  });
                }
              });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
      }
    },
    // 表格部分行被选中
    handleTableSectionChange(row) {
      this.selectedTable = row;
    },
    // 分页插件的大小改变
    handleSizeChange(val) {
      this.queryInfo.pageSize = val;
      this.getBankInfo();
    },
    // 分页插件的页数
    handleCurrentChange(val) {
      this.queryInfo.pageNo = val;
      this.getBankInfo();
    },
    // 添加题库
    addQuestionBank() {
      utils.validFormAndInvoke(
        this.$refs["addForm"],
        () => {
          questionBank.addQuestionBank(this.addForm).then((resp) => {
            if (resp.code === 20000) {
              this.getBankInfo();
              this.$notify({
                title: "Tips",
                message: resp.message,
                type: "success",
                duration: 2000,
              });
            } else {
              this.$notify({
                title: "Tips",
                message: resp.message,
                type: "error",
                duration: 2000,
              });
            }
            this.addTableVisible = false;
          });
        },
        "请检查您所填写的信息是否有误"
      );
    },
  },
};
</script>

<style scoped lang="scss">
.active3Span {
  padding: 35px 0;
  margin-left: 15px;
  font-size: 30px;
  font-weight: 300;
}
.title {
  font-weight: 600;
  font-size: 22px;
  text-align: center;
}

.chapterItem {
  border: 1px solid #c0c4cc;
  padding: 20px;
  margin-bottom: 10px;
  .operaBtn {
    padding-top: 0;
    padding-bottom: 0;
  }
}

.chapterItem1 {
  border: 1px solid #c0c4cc6b;
  padding: 20px;
  margin-bottom: 10px;
  margin-left: 90px;
  .operaBtn {
    padding-top: 0;
    padding-bottom: 0;
  }
}
</style>
